package com.esri.core.internal.tasks.oauth;

import com.sangfor.ssl.service.utils.IGeneral;
import java.util.Map;

/* loaded from: classes.dex */
public class GetTokenTaskParameters extends b {
    private static final String c = "%s/oauth2/authorize?client_id=%s&response_type=code&redirect_uri=%s";
    private static final long serialVersionUID = 1;
    private String d;
    private String e;
    private AuthType f;

    /* loaded from: classes.dex */
    private enum AuthType {
        USER,
        APPLICATION,
        DEVICE
    }

    public GetTokenTaskParameters(String str, String str2) {
        this.a = str;
        this.b = str2;
        this.f = AuthType.APPLICATION;
    }

    public GetTokenTaskParameters(String str, String str2, String str3) {
        this(str, str2, str3, null);
    }

    public GetTokenTaskParameters(String str, String str2, String str3, String str4) {
        this.e = str;
        this.a = str2;
        this.b = str3;
        this.d = (str4 == null || str4.isEmpty()) ? "urn:ietf:wg:oauth:2.0:oob" : "urn:ietf:wg:oauth:2.0:oob";
        this.f = AuthType.USER;
    }

    public GetTokenTaskParameters(String str) {
        this.b = str;
        this.f = AuthType.DEVICE;
    }

    @Override // com.esri.core.internal.tasks.oauth.b, com.esri.core.internal.tasks.f
    public Map<String, String> generateRequestParams() throws Exception {
        Map<String, String> generateRequestParams = super.generateRequestParams();
        int i = AnonymousClass1.a[this.f.ordinal()];
        if (i == 1) {
            generateRequestParams.put("grant_type", "authorization_code");
            generateRequestParams.put("code", this.e);
            generateRequestParams.put("redirect_uri", this.d);
        } else if (i == 2) {
            generateRequestParams.put("grant_type", "client_credentials");
        } else if (i == 3) {
            generateRequestParams.put("grant_type", "device");
        }
        return generateRequestParams;
    }

    /* renamed from: com.esri.core.internal.tasks.oauth.GetTokenTaskParameters$1  reason: invalid class name */
    /* loaded from: classes.dex */
    static /* synthetic */ class AnonymousClass1 {
        static final /* synthetic */ int[] a;

        static {
            int[] iArr = new int[AuthType.values().length];
            a = iArr;
            try {
                iArr[AuthType.USER.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                a[AuthType.APPLICATION.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                a[AuthType.DEVICE.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
        }
    }

    @Override // com.esri.core.internal.tasks.oauth.b, com.esri.core.internal.tasks.f
    public boolean validate() {
        boolean validate = super.validate();
        if (validate) {
            if (AnonymousClass1.a[this.f.ordinal()] != 3) {
                if (a(this.e) && a(this.a)) {
                    return false;
                }
                return validate;
            }
            return true;
        }
        return validate;
    }

    public boolean a() {
        return this.f == AuthType.DEVICE;
    }

    public static String a(String str, String str2) {
        return String.format(c, b(str), str2, "urn:ietf:wg:oauth:2.0:oob");
    }

    public static String a(String str, String str2, String str3) {
        Object[] objArr = new Object[3];
        objArr[0] = b(str);
        objArr[1] = str2;
        objArr[2] = (str3 == null || str3.isEmpty()) ? "urn:ietf:wg:oauth:2.0:oob" : "urn:ietf:wg:oauth:2.0:oob";
        return String.format(c, objArr);
    }

    private static String b(String str) {
        return str.contains(IGeneral.PROTO_HTTP_HEAD) ? str.replace(IGeneral.PROTO_HTTP_HEAD, IGeneral.PROTO_HTTPS_HEAD) : str;
    }
}
